cmake_minimum_required(VERSION 3.5.1)

# project information
project(classification_server)

# Compile options
add_compile_options(-std=c++11)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY  ".")
set(CMAKE_CXX_FLAGS_DEBUG "-fPIC -O0 -g -Wall")
set(CMAKE_CXX_FLAGS_RELEASE "-fPIC -O2 -Wall")


add_definitions(-DENABLE_DVPP_INTERFACE)
list(APPEND COMMON_DEPEND_LIB acllite avcodec avformat avdevice avutil swresample avfilter swscale)
if ($ENV{CPU_ARCH} MATCHES "aarch64")
    if(EXISTS "$ENV{INSTALL_DIR}/driver/libmedia_mini.so")
        list(APPEND COMMON_DEPEND_LIB media_mini ascend_hal c_sec mmpa)
        add_definitions(-DENABLE_BOARD_CAMARE)
        message(STATUS "arch: arm")
    endif()
endif()

# find opencv
find_package(OpenCV REQUIRED)

# Header path
include_directories(    
    $ENV{INSTALL_DIR}/runtime/include/
    $ENV{THIRDPART_PATH}/include/
    ../include/
    ${ASCEND_HOME_PATH}/aarch64-linux/include
    /usr/local/Ascend/ascend-toolkit/latest/aarch64-linux/include/
    # /home/HwHiAiUser/opencv-4.9.0-install/include/opencv4/
)

if(target STREQUAL "Simulator_Function")
    add_compile_options(-DFUNC_SIM)
endif()

# add host lib path
link_directories(
    $ENV{INSTALL_DIR}/runtime/lib64/stub
    $ENV{THIRDPART_PATH}/lib/
    $ENV{INSTALL_DIR}/driver
    /usr/local/Ascend/ascend-toolkit/latest/aarch64-linux/lib64
    /usr/local/Ascend/driver/lib64
    # /home/HwHiAiUser/opencv-4.9.0-install/lib
)

add_executable(main
        utils.cpp
        model_process.cpp
        object_detect.cpp
        dvpp_process.cpp
        dvpp_jpegd.cpp
        dvpp_resize.cpp
        module.cpp
        tcp_server.cpp
        main.cpp)

if(target STREQUAL "Simulator_Function")
    target_link_libraries(main funcsim)
else()
    target_link_libraries(main pthread ascendcl acl_dvpp stdc++ opencv_highgui opencv_core opencv_imgproc opencv_imgcodecs opencv_calib3d opencv_features2d opencv_videoio protobuf dl rt)
endif()

install(TARGETS main DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
execute_process(COMMAND ${CMAKE_COMMAND} -E copy ../scripts/param.conf ../out/param.conf)
